package com.jerkin.jieba.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import com.jerkin.jieba.GsCodeWriteData;
import com.jerkin.jieba.JiebaHelper;
import com.jerkin.jieba.model.GsCodeModel;
import com.jerkin.mynlp.MynlpHelper;
import org.apache.commons.lang3.StringUtils;
import org.apdplat.word.WordSegmenter;
import org.apdplat.word.segmentation.Word;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @className:ExcelCodeListener
 * @author:huhongzhi
 * @createTime:2021/3/15 10:49
 * @version:1.0
 */
public class ExcelCodeListener extends AnalysisEventListener<GsCodeModel> {
    @Override
    public void invoke(GsCodeModel gsCodeModel, AnalysisContext analysisContext) {
//        String name = gsCodeModel.getName();
//        List<Word> words = WordSegmenter.segWithStopWords(name);
//        System.out.println(words);
//        String value = StringUtils.join(words.stream().map(Word::getText).collect(Collectors.toList()),",");
//        System.out.println(value);
//        gsCodeModel.setSegement(JiebaHelper.segemet(gsCodeModel.getName()));
        gsCodeModel.setSegement(MynlpHelper.segemet(gsCodeModel.getName()));

        GsCodeWriteData.add(gsCodeModel);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        GsCodeWriteData.startWrite("excel_write_mynlp");
    }
}